import Vue from "vue"
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        arr: "",
        bool: false,
        b: false,
        s: "",
        i: "",
        arr6: [],
        title: "",
        seachname: "",
        Shoppingcartdata: [],
        num: "",
        queryArr: [],
        soopCar: [],
        soopAll: [],
        log: [],
        send:""
    },
    mutations: {
        submit(state, arr) {
            state.arr = arr.r
            state.i = arr.h
            localStorage.setItem("user", JSON.stringify(state.i))
        },
        sea(state, i) {
            if (i) {
                this.state.bool = false
                this.state.b = true
            }
            else {
                this.state.bool = true
                this.state.b = false
            }
        },
        xq(state, item) {
            state.arr6.push(item)
            state.seachname = item.name
        },
        qk(state) {
            state.arr6 = []
        },
        title(state, i) {
            state.title = i.title
        },
        Detailstojump(state, i) {
            state.queryArr = i
            console.log(state.queryArr);
        },
        add(state, obj) {
          
            var bool = true
            state.soopAll.forEach(res => {
                if (res.item_id == obj.item_id) {
                    bool = false;
                    res.num++
                }
            })
            if (bool) {
                state.soopAll.push(obj)
            }
      
        },
        min(state, i) {
            state.soopAll.forEach(res => {
                if (res.item_id == i.item_id && res.num > 0) {
                    res.num--
                }
            })

        },
        updateCar(state, id) {
            state.soopAll.forEach(res => {
                if (res.item_id == id) {
                    res.num++
                }
            })
        },
        log(state, res) {
            state.log = res
        },
        sendImg(state,i){
           state.send =i

        }
    },
    getters: {},
    modules: {},
    plugins: [createPersistedState({
        storage: window.sessionStorage, // 存储方式改为sessionStorage,或者可以改为长久储存localStorage
    })],
})